﻿@using Abc.Core;
@using Abc.Core.Entities;


@{
    ViewData["Title"] = "邮件发送配置";
}
<div class="layui-row layui-col-space10">
    <div class="layui-card" id="headsearch_EmailSendConfig">
        <div class="layui-card-body" style="padding: 0px;">
            <form class="layui-form" action="javascript:;" id="queryform_EmailSendConfig">

                <div class="layui-inline">
                    <label class="layui-form-mid">关键词</label>
                    <div class="layui-input-inline" style="width: 300px;">
                        <input type="text" id="KeyWords" name="KeyWords" placeholder="输入关键词模糊查询" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-mid">创建日期</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" name="StartDate" id="StartDate_EmailSendConfig" placeholder="开始日期">
                    </div>
                    <div class="layui-form-mid">-</div>
                    <div class="layui-input-inline">
                        <input class="layui-input" name="EndDate" id="EndDate_EmailSendConfig" placeholder="结束日期">
                    </div>
                </div>
                <div class="layui-inline">
                    <div id="search_EmailSendConfig" class="layui-btn submitbtn" lay-submit lay-filter="search_EmailSendConfig"> <i class="layui-icon layui-icon-search"></i>查找</div>
                    <button id="reset_EmailSendConfig" type="reset" class="layui-btn layui-btn-primary"><i class="layui-icon layui-icon-refresh">重置</i></button>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 0px;">
            <table id="listData_EmailSendConfig" class="layui-hide" lay-filter="listData_EmailSendConfig"></table>
        </div>
    </div>
</div>
<script type="text/html" id="toolbar_EmailSendConfig">
    <div class="layui-btn layui-btn-primary layui-btn-md" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>新增</div>
    <div class="layui-btn layui-btn-danger layui-btn-md" lay-event="batchRemove"><i class="layui-icon layui-icon-delete"></i>删除</div>
</script>
<script type="text/html" id="tablebar_EmailSendConfig">
    <div class="layui-btn layui-btn-sm layui-btn-primary more_{{d.Id}}"><i class="layui-icon layui-icon-triangle-d">更多</i></div>
</script>

@*自动生成开关代码*@
@* 是否启用 *@
@*<script type="text/html" id="tpl_IsEnable_EmailSendConfig">
    <input type="checkbox" name="IsEnable_EmailSendConfig" objid="{{d.Id}}" lay-skin="switch" title="启用|禁用" lay-filter="IsEnable_EmailSendConfig" {{ d.IsEnable ? 'checked' : '' }}>
    </script>*@
@* 是否包含Html代码 *@
@*<script type="text/html" id="tpl_EmailIsHtml_EmailSendConfig">
    <input type="checkbox" name="EmailIsHtml_EmailSendConfig" objid="{{d.Id}}" lay-skin="switch" title="启用|禁用" lay-filter="EmailIsHtml_EmailSendConfig" {{ d.EmailIsHtml ? 'checked' : '' }}>
    </script>*@
@* 是否启用SSL加密 *@
@*<script type="text/html" id="tpl_EmailIsSsl_EmailSendConfig">
    <input type="checkbox" name="EmailIsSsl_EmailSendConfig" objid="{{d.Id}}" lay-skin="switch" title="启用|禁用" lay-filter="EmailIsSsl_EmailSendConfig" {{ d.EmailIsSsl ? 'checked' : '' }}>
    </script>*@
@* 默认假删除 *@
@*<script type="text/html" id="tpl_IsDeleted_EmailSendConfig">
    <input type="checkbox" name="IsDeleted_EmailSendConfig" objid="{{d.Id}}" lay-skin="switch" title="启用|禁用" lay-filter="IsDeleted_EmailSendConfig" {{ d.IsDeleted ? 'checked' : '' }}>
    </script>*@
<script type="text/html" id="tpl_Type_EmailSendConfig">
    {{# if(d.Type==1){ }}
      <span class="layui-badge layui-bg-orange">IPV4</span>
    {{# }else { }}
      <span class="layui-badge layui-bg-blue">IPV6</span>
    {{# } }}
</script>

@section Scripts{
    <script>
        layui.use(['table', 'form', 'jquery', 'drawer', 'dropdown', 'layer'], function () {
            let $ = layui.jquery;
            let layer = layui.layer;
            let table = layui.table;
            let form = layui.form;
            let drawer = layui.drawer;
            let dropdown = layui.dropdown;

            abc.indexInit({ reset: '#reset_EmailSendConfig', search: '#search_EmailSendConfig' });
            //监听头工具栏事件
            table.on('toolbar(listData_EmailSendConfig)', function (obj) {
                if (obj.event === 'add') {
                    abc.open({ title: '新增', url: '@(Url.Action("Add", "HtEmailSendConfig", new { area = "HtAdmin" }))', area: ['100%', '98%'], end: refresh_EmailSendConfig });
                } else if (obj.event === 'refresh') {
                    refresh_EmailSendConfig();
                } else if (obj.event === 'batchRemove') {
                    var ids = abc.getSelectDataIds(table, "listData_EmailSendConfig");
                    if (ids.length === 0) {
                        layer.msg("未选中数据", { icon: 3, time: 1000 });
                        return false;
                    }
                    abc.delete({ url: "@(Url.Action("BatchDelete", "HtEmailSendConfig", new { area = "HtAdmin" }))", data: { ids: ids }, success: function () { refresh_EmailSendConfig() } });
                }
            });
            table.on('tool(listData_EmailSendConfig)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的DOM对象
                if (layEvent === 'delete') { //删除
                    abc.delete({url:"@(Url.Action("BatchDelete", "HtEmailSendConfig", new { area = "HtAdmin" }))",data:{ ids: data.Id },success:function(){obj.del();refresh_EmailSendConfig()}});
                } else if (layEvent === 'edit') { //编辑
                    edit_EmailSendConfig(obj);
                } else if (obj.event === 'save') {
                    if (editrowids.indexOf(obj.data.Id) == -1) {
                        abc.failure("请先修改后再保存")
                    }
                    else {
                        abc.success("保存成功消息")
                    }
                }else if (obj.event === 'more') {
                    dropdown.render({
                        elem: this, // 触发事件的 DOM 对象
                        show: true, // 外部事件触发即显示
                        data: [
                            { title: '详情', id: 'edit' },
                            { title: '删除', id: 'delete' },
                        ]
                        , click: function (menudata) {

                            if (menudata.id === 'edit') {
                                edit_EmailSendConfig(obj);
                            } if (menudata.id === 'delete') {
                               abc.delete({ url: "@(Url.Action("BatchDelete"))", data: { ids: obj.data.Id }, success: function () { refresh_EmailSendConfig() } });
                            }

                        }
                    });
                }

            });
            //table 行双击事件
            table.on('rowDouble(listData_EmailSendConfig)', function (obj) { edit_EmailSendConfig(obj); });
            //table 行中的事件监听
            //编辑
            function edit_EmailSendConfig(obj) {
                abc.open({ title: '编辑', url: '@(Url.Action("Info", "HtEmailSendConfig", new { area = "HtAdmin" }))/' + obj.data.Id, area: ['100%', '98%'], end: refresh_EmailSendConfig });
            }


            //Table 初始化
            //, templet: '#tpl_user'
            var cols = [
                [
                    //, templet: '#tpl_IsEnable_EmailSendConfig'
                    //{ type: 'checkbox', fixed: 'left'},
                    //{ type: 'numbers', fixed: 'left', rowspan: 1 },
                    //{ title: '标签', 'toolbar': '#tplable', fixed: 'left', width: 100 },
                    //{ title: 'ID', field: 'Id', width: 60 },


                    { title: 'ID', field: 'Id', width: 60, align: 'center' },

                    { title: 'SMTP服务器', field: 'EmailSmtpHost', minWidth: 60, align: 'center' },
                    { title: '邮件服务器Smtp端口', field: 'EmailSmtpPort', minWidth: 60, align: 'center' },
                    { title: '邮箱账号', field: 'EmailAccount', minWidth: 60, align: 'center' },
                    { title: '是否启用', field: 'IsEnableName', width: 60, align: 'center' },// templet: '#tpl_IsEnable_EmailSendConfig'
                    //{ title: '邮箱密码', field: 'EmailPassword', minWidth: 60, align:'center' },
                    { title: '是否包含Html代码', field: 'EmailIsHtmlName', width: 60, align: 'center' },// templet: '#tpl_EmailIsHtml_EmailSendConfig'
                    { title: '发送者显示名', field: 'EmailDisplayName', minWidth: 60, align: 'center' },
                    { title: '是否启用SSL加密', field: 'EmailIsSslName', width: 60, align: 'center' },// templet: '#tpl_EmailIsSsl_EmailSendConfig'
                    { title: '备注', field: 'Remark', minWidth: 60, align: 'center' },
                    { title: '创建用户ID', field: 'CreatorUserId', minWidth: 60, align: 'center', hide: true },
                    { title: '创建用户', field: 'CreatorUserName', minWidth: 60, align: 'center', hide: true },
                    { title: '创建时间', field: 'CreationTime', width: 130, align: 'center', hide: true },
                    //{ title: '更新用户ID', field: 'UpdateUserId', minWidth: 60, align:'center' ,hide:true},
                    { title: '更新用户', field: 'UpdateUserName', minWidth: 60, align: 'center', hide: true },
                    { title: '更新时间', field: 'UpdateTime', width: 130, align: 'center', hide: true },
                    //{ title: '默认假删除', field: 'IsDeletedName', width: 60, align:'center' },// templet: '#tpl_IsDeleted_EmailSendConfig'
                    //{ title: '删除用户ID', field: 'DeletedUserId', minWidth: 60, align:'center' },
                    //{ title: '删除用户', field: 'DeletedUserName', minWidth: 60, align:'center' },
                    //{ title: '删除时间', field: 'DeletedTime', width: 130, align:'center',hide:true },

                    { title: '操作', fixed: 'right', width: 80, align: 'left', toolbar: '#tablebar_EmailSendConfig' }
                ]
            ];
            //表格下拉菜单

            //初始化table
            abc.initTable("listData_EmailSendConfig", cols, { title: '邮件发送配置', toolbar: '#toolbar_EmailSendConfig' });

            //提交搜索
            form.on('submit(search_EmailSendConfig)', function (obj) {
                abc.search('listData_EmailSendConfig', '@(Url.Action("GetList", "HtEmailSendConfig", new { area = "HtAdmin" }))', obj.field, { method: "post", done: tableDone_EmailSendConfig });
                return false;
            });
            $("#search_EmailSendConfig").click();//初始化完成后 搜索一次
            function refresh_EmailSendConfig() {
                //table.reload("listData_EmailSendConfig");
                $("#search_EmailSendConfig").click();
            };
            //IsEnable 开关事件
            form.on('switch(IsEnable_EmailSendConfig)', function (obj) {
                //console.log(this, obj, { Id: $(this).attr('objid'), isEnable: obj.elem.checked });
                abc.post({ url: '@(Url.Action("SetEnable", "HtEmailSendConfig", new { area = "HtAdmin" }))', data: { id: $(this).attr('objid'), state: obj.elem.checked, type: 'isenable' } });
            });
        @*自动生成开关代码*@
                // 是否启用 开关事件
        @*form.on('switch(IsEnable_EmailSendConfig)', function (obj) {
            //console.log(this, obj, { Id: $(this).attr('objid'), isEnable: obj.elem.checked });
            abc.post({ url: '@(Url.Action("SetEnable","HtEmailSendConfig", new { area = "HtAdmin" }))', data: { id: $(this).attr('objid'), state:obj.elem.checked,type:'IsEnable.ToLower())' }});
            });*@
                // 是否包含Html代码 开关事件
        @*form.on('switch(EmailIsHtml_EmailSendConfig)', function (obj) {
            //console.log(this, obj, { Id: $(this).attr('objid'), isEnable: obj.elem.checked });
            abc.post({ url: '@(Url.Action("SetEnable","HtEmailSendConfig", new { area = "HtAdmin" }))', data: { id: $(this).attr('objid'), state:obj.elem.checked,type:'EmailIsHtml.ToLower())' }});
            });*@
                // 是否启用SSL加密 开关事件
        @*form.on('switch(EmailIsSsl_EmailSendConfig)', function (obj) {
            //console.log(this, obj, { Id: $(this).attr('objid'), isEnable: obj.elem.checked });
            abc.post({ url: '@(Url.Action("SetEnable","HtEmailSendConfig", new { area = "HtAdmin" }))', data: { id: $(this).attr('objid'), state:obj.elem.checked,type:'EmailIsSsl.ToLower())' }});
            });*@
                // 默认假删除 开关事件
        @*form.on('switch(IsDeleted_EmailSendConfig)', function (obj) {
            //console.log(this, obj, { Id: $(this).attr('objid'), isEnable: obj.elem.checked });
            abc.post({ url: '@(Url.Action("SetEnable","HtEmailSendConfig", new { area = "HtAdmin" }))', data: { id: $(this).attr('objid'), state:obj.elem.checked,type:'IsDeleted.ToLower())' }});
            });*@

                    //事件集合
                    var active = {
                example: function () {
                },
                example1: function () {
                }
            };

            //表格下拉菜单
            //tableDone_EmailSendConfig(res, curr, count) {}
            function tableDone_EmailSendConfig(res, curr, count) {
                
            }

            //注册layui-btn 事件
            $('.layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

            // 初始化日期选择
            //abc.initDate('StartDate_EmailSendConfig,EndDate_EmailSendConfig');


        });
    </script>
}


